package com.skytech.tax.customsdatawarehouse.singlewindow.customsdeclarations.resource;

import com.skytech.tax.customsdatawarehouse.singlewindow.customsdeclarations.domain.entity.IECustomsDeclarationSimple;
import com.skytech.tax.customsdatawarehouse.singlewindow.customsdeclarations.domain.service.IECustomsDeclarationService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Lianhong
 * @since 2021/6/8
 * 单一窗口 - 进出口关单资源服务
 */
@RestController("singleWindow.ieCustomsDeclarationResource")
@RequestMapping("/single-window/ie-customs-declaration")
public class IECustomsDeclarationResource {

    @Resource(name = "singleWindow.ieCustomsDeclarationService")
    private IECustomsDeclarationService ieCustomsDeclarationService;

    /**
     * 查询进出口关单列表
     *
     * @return 进出口关单列表
     */
    @GetMapping
    public String customsDeclarations() {
        return ieCustomsDeclarationService.getCustomsDeclarations();
    }

    /**
     * 根据统一编号查询进出口关单列表
     *
     * @return 进出口关单列表
     */
    @PutMapping
    public String customsDeclarations(@RequestBody List<String> cusCiqNos) {
        return ieCustomsDeclarationService.getCustomsDeclarations(cusCiqNos);
    }

    /**
     * 保存进出口报关单信息
     *
     * @param declaration 进出口报关单
     * @return 进出口报关单
     */
    @PostMapping
    public String saveCustomsDeclaration(@RequestBody String declaration) {
        return ieCustomsDeclarationService.saveCustomsDeclaration(declaration);
    }

    /**
     * 查询报关单信息
     *
     * @param cusCiqNo 统一编号
     * @return 进出口报关单
     */
    @GetMapping("{cusCiqNo}")
    public String customsDeclaration(@PathVariable String cusCiqNo) {
        return ieCustomsDeclarationService.getCustomsDeclaration(cusCiqNo);
    }

    /**
     * 删除报关单信息
     *
     * @param cusCiqNo 统一编号
     */
    @DeleteMapping("{cusCiqNo}")
    public void deleteCustomsDeclaration(@PathVariable String cusCiqNo) {
        ieCustomsDeclarationService.deleteByCusCiqNo(cusCiqNo);
    }

    /**
     * 判断是否存在进出口报关单
     *
     * @return cusCiqNo-01,cusCiqNo-02,...
     */
    @PostMapping("exists")
    public String existsCustomsDeclarations(@RequestBody List<IECustomsDeclarationSimple> simpleList) {
        return ieCustomsDeclarationService.existsCustomsDeclarations(simpleList);
    }

    /**
     * 判断是否存在进出口报关单
     *
     * @param cusCiqNo     统一编号
     * @param updateTime   更新时间
     * @param cusDecStatus 报关状态
     * @return 是否存在
     */
    @GetMapping("{cusCiqNo}/exists")
    public boolean existsCustomsDeclaration(@PathVariable String cusCiqNo,
                                            @RequestParam("updateTime") String updateTime,
                                            @RequestParam(value = "cusDecStatus", required = false) String cusDecStatus) {
        return ieCustomsDeclarationService.existsCustomsDeclaration(cusCiqNo, updateTime, cusDecStatus);
    }

    /**
     * 查询报关单文件名
     *
     * @param cusCiqNo 统一编号
     * @return 阿里云存储文件名
     */
    @GetMapping("{cusCiqNo}/file")
    public String customsDeclarationFile(@PathVariable String cusCiqNo) {
        return ieCustomsDeclarationService.customsDeclarationFile(cusCiqNo);
    }

    /**
     * 删除报关单文件名
     *
     * @param cusCiqNo 统一编号
     */
    @DeleteMapping("{cusCiqNo}/file")
    public void deleteCustomsDeclarationFile(@PathVariable String cusCiqNo) {
        ieCustomsDeclarationService.deleteCustomsDeclarationFile(cusCiqNo);
    }

    /**
     * 保存报关单文件名
     *
     * @param cusCiqNo   统一编号
     * @param storedFile 存储文件名称
     */
    @PostMapping("{cusCiqNo}/file")
    public void saveCustomsDeclarationFile(@PathVariable String cusCiqNo, @RequestBody String storedFile) {
        ieCustomsDeclarationService.saveCustomsDeclarationFile(cusCiqNo, storedFile);
    }


    /**
     * 报关单文件是否已存储
     *
     * @param cusCiqNo 统一编号
     */
    @GetMapping("{cusCiqNo}/file/stored")
    public boolean customsDeclarationFileStored(@PathVariable String cusCiqNo) {
        return ieCustomsDeclarationService.customsDeclarationFileStored(cusCiqNo);
    }

    /**
     * 保存报关单-回执通知书
     */
    @PostMapping("receipt-notice")
    public String saveReceiptNotice(@RequestBody String ret) {
        return ieCustomsDeclarationService.saveReceiptNotice(ret);
    }


    /**
     * 查询报关单-回执通知书文件名
     *
     * @param cusRetSeqNo 回执通知书编号
     * @return 阿里云存储文件名
     */
    @GetMapping("receipt-notice/{cusRetSeqNo}/file")
    public String receiptNoticeFile(@PathVariable String cusRetSeqNo) {
        return ieCustomsDeclarationService.receiptNoticeFile(cusRetSeqNo);
    }

    /**
     * 保存报关单-回执通知书文件名
     *
     * @param cusRetSeqNo 回执通知书编号
     * @param storedFile  存储文件名称
     */
    @PostMapping("receipt-notice/{cusRetSeqNo}/file")
    public void saveReceiptNoticeFile(@PathVariable String cusRetSeqNo, @RequestBody String storedFile) {
        ieCustomsDeclarationService.saveReceiptNoticeFile(cusRetSeqNo, storedFile);
    }

    /**
     * 报关单-回执通知书文件是否已存储
     *
     * @param cusRetSeqNo 回执通知书编号
     */
    @GetMapping("receipt-notice/{cusRetSeqNo}/file/stored")
    public boolean receiptNoticeFileStored(@PathVariable String cusRetSeqNo) {
        return ieCustomsDeclarationService.receiptNoticeFileStored(cusRetSeqNo);
    }


    /**
     * 查询报关单-随附单据文件名
     *
     * @param attEdocId 随附单据ID
     * @return 阿里云存储文件名
     */
    @GetMapping("attached-doc/{attEdocId}/file")
    public String attachedDocFile(@PathVariable String attEdocId) {
        return ieCustomsDeclarationService.attachedDocFile(attEdocId);
    }


    /**
     * 删除报关单-随附单据文件名
     *
     * @param attEdocId 随附单据ID
     */
    @DeleteMapping("attached-doc/{attEdocId}/file")
    public void deleteAttachedDocFile(@PathVariable String attEdocId) {
        ieCustomsDeclarationService.deleteAttachedDocFile(attEdocId);
    }


    /**
     * 保存报关单-随附单据文件名
     *
     * @param attEdocId  随附单据ID
     * @param storedFile 存储文件名称
     */
    @PostMapping("attached-doc/{attEdocId}/file")
    public void saveAttachedDocFile(@PathVariable String attEdocId, @RequestBody String storedFile) {
        ieCustomsDeclarationService.saveAttachedDocFile(attEdocId, storedFile);
    }

    /**
     * 报关单-随附单据文件是否已存储
     *
     * @param attEdocId 随附单据ID
     */
    @GetMapping("attached-doc/{attEdocId}/file/stored")
    public boolean attachedDocFileStored(@PathVariable String attEdocId) {
        return ieCustomsDeclarationService.attachedDocFileStored(attEdocId);
    }

    /**
     * 根据统一编号查询是否存在随附单据
     *
     * @param cusCiqNos 统一编号
     */
    @PostMapping("attached-doc")
    public String attachedDocExists(@RequestBody List<String> cusCiqNos) {
        return ieCustomsDeclarationService.attachedDocExists(cusCiqNos);
    }
}
